package com.ruoyi.face.domain;

import cn.hutool.core.codec.Base64;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

public class Voices {

    @JsonProperty(value = "voice_list")
    private List<Voice> voiceList = new ArrayList<>();

    public List<Voice> getVoiceList() {
        return voiceList;
    }

    public void setVoiceList(List<Voice> voiceList) {
        this.voiceList = voiceList;
    }

    public void addVoice(Integer id, String filePath, String remark, String ttsText) {
        String data;
        try {
            data = Base64.encode(Files.readAllBytes(Paths.get(filePath)));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        voiceList.add(new Voice(id, data, remark, ttsText));
    }

    public class Voice {

        private Integer id;

        @JsonProperty(value = "audio_data")
        private String audioData;

        @JsonProperty(value = "audio_remark")
        private String audioRemark;

        @JsonProperty(value = "tts_text")
        private String ttsText;

        public Voice() {

        }

        public Voice(Integer id, String audioData, String remark, String ttsText) {
            this.id = id;
            this.audioData = audioData;
            this.audioRemark = remark;
            this.ttsText = ttsText;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getAudioData() {
            return audioData;
        }

        public void setAudioData(String audioData) {
            this.audioData = audioData;
        }

        public String getAudioRemark() {
            return audioRemark;
        }

        public void setAudioRemark(String audioRemark) {
            this.audioRemark = audioRemark;
        }

        public String getTtsText() {
            return ttsText;
        }

        public void setTtsText(String ttsText) {
            this.ttsText = ttsText;
        }
    }
}
